/**
 *  Copyright 2010 ShenYang voole Co. Ltd.
 *  All right reserved. 
 */
package com.dianning.dao.hibernate;


import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dianning.bean.AdAds;
import com.dianning.bean.AdSpace;
import com.dianning.bean.Admin;
import com.dianning.bean.Area;
import com.dianning.bean.Channel;
import com.dianning.bean.Credit;
import com.dianning.bean.Info;
import com.dianning.bean.Message;
import com.dianning.bean.Money;
import com.dianning.bean.UserDetail;
import com.dianning.bean.Visitor;
import com.dianning.comm.Constant;
import com.dianning.dao.AdAdsDAO;
import com.dianning.dao.AdSpaceDAO;
import com.dianning.dao.AdminDAO;
import com.dianning.dao.AreaDAO;
import com.dianning.dao.ChannelDAO;
import com.dianning.dao.CreditDAO;
import com.dianning.dao.InfoDAO;
import com.dianning.dao.MessageDAO;
import com.dianning.dao.MoneyDAO;
import com.dianning.dao.UserDetailDAO;
import com.dianning.dao.VisitorDAO;

/**
 * 功能描述:用户扩展信息操作实现
 *
 * 创建日期 Apr 10, 2010
 *
 * @author zhangbaochao
 *
 * @version 1.0
 *
 */
public class UserDetailHibernateDAO extends HibernateDaoSupport implements UserDetailDAO {

	private static final String LOAD_BY_UID = "from UserDetail where uid = ?";
	
	/**
	 * 保存UserDetail对象
	 * 
	 * @param userDetail
	 * 			UserDetail对象
	 * @return UserDetail
	 * 			UserDetail对象
	 */
	public UserDetail saveUserDetail(UserDetail userDetail){
		this.getHibernateTemplate().save(userDetail);
		return userDetail;
	}
	/**
	 * 保存或更新UserDetail对象
	 * 
	 * @param userDetail
	 * 			UserDetail对象
	 * @return UserDetail
	 * 			UserDetail对象
	 */
	public UserDetail saveOrUpdateUserDetail(UserDetail userDetail){
		this.getHibernateTemplate().saveOrUpdate(userDetail);
		return userDetail;
	}
	/**
	 * 保存UserDetail对象
	 * 
	 * @param userDetail
	 * 			UserDetail对象
	 * @return UserDetail
	 * 			UserDetail对象
	 */
	public UserDetail updateUserDetail(UserDetail userDetail){
		this.getHibernateTemplate().update(userDetail);
		return userDetail;
	}
	
	/**
	 * 根据主键ID获取UserDetail对象
	 * 
	 * @param iid
	 * 			主键ID
	 * @return UserDetail
	 * 			UserDetail对象
	 */
	public UserDetail findUserDetailByUid(long uid){
		List l = this.getHibernateTemplate().find(LOAD_BY_UID,uid);
		if(l == null || l.isEmpty()){
			return null;
		}else{
			return (UserDetail) l.get(0);
		}
	}
}
